package com.tjbklx1.thread.chap03.practise06;

import java.util.Random;

public class ServerThread extends Thread {
	private final Random random;

	private final RequestQueue requestQueue;

	public ServerThread(String name, RequestQueue requestQueue, long seed) {
		super(name);
		this.random = new Random(seed);
		this.requestQueue = requestQueue;
	}

	@Override
	public void run() {
		try {
			for (int i = 0; i < 10000; i++) {
				Request request = requestQueue.getRequest();
				System.out.println(Thread.currentThread().getName()
						+ " handles " + request);
				Thread.sleep(random.nextInt(100));
			}
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}
